package others.swing.p001;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

/**
 * 图书管理系统
 * 项目详细介绍：https://blog.csdn.net/WeiHao0240/article/details/120819916
 */
class Book extends JFrame implements ActionListener {
    JButton QueryScore = new JButton("图书查询");
    JButton QueryXuefen = new JButton("图书入库");
    JButton jiangfa = new JButton("图书删除");
    JButton xuanke = new JButton("图书概览");
    JButton gaiMima = new JButton("修改密码");
    //菜单栏
    JMenuBar mb = new JMenuBar();
    //用来填放子模块
    JPanel jp = new JPanel();
    Container cp = getContentPane();
    String username;

    Book() {
    }

    Book(String username) {
        this.username = username;
        mb.add(QueryScore);
        mb.add(QueryXuefen);
        mb.add(jiangfa);
        mb.add(xuanke);
        mb.add(gaiMima);
        cp.add(mb, "North");

        // 设置边框
        jp.setBorder(BorderFactory.createTitledBorder(BorderFactory
                        .createLineBorder(Color.blue, 2), null,
                TitledBorder.CENTER, TitledBorder.TOP));
        jp.setLayout(new BorderLayout());
        JLabel JL=new JLabel("<html><font color=#CC00FF size='7'><i>欢迎使用“图书管理系统”</i></font>",SwingConstants.CENTER);
        jp.add(JL,"North");
        JScrollPane scrollpane = new JScrollPane(jp);
        cp.add(scrollpane);
        setTitle("欢迎登陆");

        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screen = kit.getScreenSize();
        /*取得显示器窗口的宽度*/
        int x = screen.width;
        /*取得显示器窗口的高度*/
        int y = screen.height;
        /*让系统窗口平铺整个显示器窗口*/
        //setSize(x,y);

        setSize(600, 600);
        int xcenter = (x - 600) / 2;
        int ycenter = (y - 600) / 2;
        setLocation(xcenter, ycenter);/*显示在窗口中央*/

        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //注册临听器
        QueryScore.addActionListener(this);
        QueryXuefen.addActionListener(this);
        jiangfa.addActionListener(this);
        xuanke.addActionListener(this);
        gaiMima.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();
        if (cmd.equals("图书查询")) {
            new QueryBook();
        }
        if (cmd.equals("图书入库")) {
            new BookIn();
        }
        if (cmd.equals("图书删除")) {
            new RemoveBook();
        }
        if (cmd.equals("图书概览")) {
            new BookBrower().showRecord();
        }
        if (cmd.equals("修改密码")) {
            new UpdateMima(username);
        }
    }

    public static void main(String[] args) {
        new Book("");
    }
}

